package utils;

import com.google.gdata.data.appsforyourdomain.provisioning.UserEntry;
import sample.appsforyourdomain.AppsForYourDomainClient;

public class UsersInfo {

	public static String getFullName(String EmailID) {

		if (EmailID.indexOf("@") <= 0) return "";
		
		String strDomain = System.getProperty("DOMAIN");
		String strUserName = System.getProperty("ADMIN_USERNAME");
		String strPwd = System.getProperty("ADMIN_PWD");
		String strUser_ID = EmailID.substring(0, EmailID.indexOf("@"));
		String strFull_Name = "";
		UserEntry entry = null;

		try {

			AppsForYourDomainClient client = new AppsForYourDomainClient(
					strUserName, strPwd, strDomain);
			entry = client.retrieveUser(strUser_ID);
			if (entry != null)
				strFull_Name = entry.getName().getGivenName().toString().trim()
						+ " "
						+ entry.getName().getFamilyName().toString().trim();

		} catch (Exception e) {
			e.printStackTrace();
		}

		return strFull_Name;
	}

	public static String getMultiFullName(String EmailID) {

		String []Name;
		String delimiter = ";";
		Name = EmailID.split(delimiter);
		String strFull_Name = "";
		String temp = "";
		for(int i =0; i < Name.length ; i++){
			temp = Name[i].trim();
			if ( temp.equals("") || temp.equals(";") ) break;
			if ( i == 0 )
				strFull_Name = getFullName(temp);
			else
				strFull_Name = strFull_Name + ";" + getFullName(temp);
		}
		
		return strFull_Name;
	}
	
}